package com.up.blog.controller;

import com.alibaba.fastjson.JSON;
import com.up.blog.domain.Infobean;
import com.up.blog.service.GetArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
@Controller
public class DraftPublishController{
    @Autowired
    private GetArticlesService getArticles;
    @RequestMapping(value = "/draftpublish", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String findUserById(HttpServletRequest req, HttpServletResponse resp) {
        String id=req.getParameter("id");
        System.out.println(id);
        Infobean infobean=new Infobean();
        String ret=null;
        try {
            int u=getArticles.draftpublish(id);
            if(u>0){
                infobean.setCode(0);
                infobean.setMsg("发布成功！");
            }else {
                infobean.setCode(1);
                infobean.setMsg("发布失败！");
            }
            ret=JSON.toJSONString(infobean);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ret;
    }
}
